package main

import (
	"fmt"
	"time"
)

func main() {
	/*//time.NewTimer  == time.After
	timer := time.NewTimer(time.Second)
	fmt.Println(time.Now())
	timerchan2 := timer.C
	fmt.Println(<-timerchan2)

	timer2 := time.NewTimer(time.Second * 3)
	go func() {
		<-timer2.C //本来3S后停止  有stop函数 可以提前停止
		fmt.Println("子程序end。。。")
	}()
	time.Sleep(time.Second)
	stop := timer2.Stop()
	if stop { //停止或结束返回 false，否则返回true
		fmt.Println("timer2停止了")
	}*/
	//间隔多长时间后输出时间
	timechan := time.After(time.Second * 2)
	fmt.Println(time.Now())

	chantime := <-timechan
	fmt.Println(chantime)

	// 间隔一定时间后执行一个函数
	time.AfterFunc(time.Second*3, test8)

	time.Sleep(time.Second * 4)
}
func test8() {
	fmt.Println("time时间后执行")
}
